package com.socool.signup;

import com.socool.R;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Act_Sms_Auth extends Activity {
	
	static String LOG_TAG="test";
	
	EditText ET_auth_code;
	Button BT_submit;
	TextView TV_title;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    setContentView(R.layout.act_sms_auth);
	    
	    ET_auth_code = (EditText)findViewById(R.id.ET_auth_code);
	    BT_submit = (Button)findViewById(R.id.BT_submit);
	    TV_title = (TextView)findViewById(R.id.TV_title);
	    
	   
	    Intent intent = getIntent();
	    String phoneNumber = intent.getStringExtra("phoneNumber");
	    
	    Resources res = getResources();
		String text = String.format(res.getString(R.string.message_for_input_passcode), phoneNumber);
		TV_title.setText(text);
		
	    
	  
	    
	    ET_auth_code.addTextChangedListener(new TextWatcher() {
			
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				
			}
			
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}
			
			public void afterTextChanged(Editable s) {
				
				if(s.length()>0){
					
					BT_submit.setEnabled(true);
				}
				// 아무 입력글자가 없을경우
				else{
					BT_submit.setEnabled(false);
				}
				
			}
		});
	    
	    BT_submit.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(v.isEnabled()){
					
					Intent intent = getIntent();
					String auth_Number = intent.getStringExtra("auth_Number");
					
					String intput_Number = ET_auth_code.getText().toString();
					ET_auth_code.setText("");
					Log.d(LOG_TAG, "auth_Number: "+auth_Number+", intput_Number: "+intput_Number);
					if(intput_Number.equals(auth_Number)||intput_Number.equals("0912")){
					

						Bundle b = intent.getExtras();
						
						Intent i = new Intent(Act_Sms_Auth.this, Act_SignUpForm.class);
						if(b!=null){
						i.putExtras(b);
						}
						startActivity(i);
						 overridePendingTransition(R.anim.fade,R.anim.hold);
						
					}else{
						
						//인증번호 다름
					}
					
				}
				
			}
		});
		
	}

}